package com.betterwood.dragon.service;

import com.betterwood.dragon.dao.UserDao;
import com.betterwood.dragon.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Optional;

/**
 * @author zhengyanhua
 * @create 2021-03-18 14:05
 */
@Service(value = "userService")
public class UserService {

    @Autowired
    private UserDao userDao;

    public User insertUser(User record) {
        return userDao.insert(record);
    }

    public void update(User record) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        userDao.updateUser(record);

    }

    public void deleteById(String id) {
        userDao.deleteById(id);
    }

    public User save(User record){
        return userDao.save(record);
    }

    public List<User> findAll() {
        return userDao.findAll();
    }

    public User findOne(String id) {
        return userDao.findById(id).get();
    }

    public User findOneByPhone(String phone) {
        return userDao.findByPhone(phone);
    }

    public User findByMinAppOpenId(String minAppOpenId) {
        return userDao.getByMinappOpenId(minAppOpenId);
    }

    public Optional<User> findOneById(String id) {
        return userDao.findById(id);
    }

    public List<User> findByUserStatus(Integer userStatus) {

        return userDao.findByUserStatus(userStatus);
    }

}
